<!-- Dinamic Contacts -->
<script>

function addContact() {

 			var $value = parseInt(document.getElementById('sizecontact').value);
			var $contacts = new Array();
 	    	if($value < 6) {

 	    	//guarda o valor dos fields
			for(var $i = 1 ; $i < $value + 1; $i ++) {
				if(document.getElementById('Contact_'+$i+'_contact') != null) {
 	 	    	var $contact = new Array(4);
 	 	    	$contact[0] = document.getElementById('Contact_'+$i+'_contact').value;
 	 	    	$contact[1] = document.getElementById('Contact_'+$i+'_fone1').value;
 	 	    	$contact[2] = document.getElementById('Contact_'+$i+'_fone2').value;
 	 	    	$contact[3] = document.getElementById('Contact_'+$i+'_type').value;

 	 	    	$contacts.push( $contact);
				}
 	    	}	


 	 	    //cria novos fields
 	 	    $value++;
 			document.getElementById('sizecontact').value = parseInt(document.getElementById('sizecontact').value) + 1;
  			$content = '<table><tr><td><label for="Contact_'+ $value +'_contact">Nome*</label></td>'+
						'<td><label for="Contact_'+ $value +'_fone1">Telefone 1</label></td>'+
						'<td><label for="Contact_'+ $value +'_fone2">Telefone 2</label></td>'+
						'<td><label for="Contact_'+ $value +'_type">Tipo</label></td></tr>'+
						'<tr><td><input class="span3" maxlength="250" name="Contact['+
						$value+'][contact]" id="Contact_'+$value+'_contact" type="text"></td>'
 			+'<td><input class="span2" maxlength="45" name="Contact['+$value+'][fone1]" id="Contact_'+$value+'_fone1" type="text"></td>'
 			+'<td><input class="span2" maxlength="45" name="Contact['+$value+'][fone2]" id="Contact_'+$value+'_fone2" type="text"></td>'
 			+'<td><input class="span3" maxlength="45" name="Contact['+$value+'][type]" id="Contact_'+$value+'_type" type="text"></td></tr></table>';	    	
				
 	    	document.getElementById('contacts').innerHTML = document.getElementById('contacts').innerHTML + $content;

 	    	//seta nos fields
			for(var $i = 0 ; $i < $value - 1; $i ++) {
 	 	    	var $contact = $contacts[$i];
 	 	    		$cont = $i + 1;
 	 	    	if($contact != null && document.getElementById('Contact_'+$cont+'_contact') != null) {
 	 	    		document.getElementById('Contact_'+$cont+'_contact').value = $contact[0];
 	 	    		document.getElementById('Contact_'+$cont+'_fone1').value = $contact[1];
 	 	    		document.getElementById('Contact_'+$cont+'_fone2').value = $contact[2];
 	 	    		document.getElementById('Contact_'+$cont+'_type').value = $contact[3];
 	 	    	}
 	    	}
 	    	
 	    	} else {
 	    		window.alert("É permitido cadastrar apenas 6 contatos para um Time");
 	    	}

	
 	    	
}

</script>
<input id="sizecontact" name="sizecontact" type="hidden"
	value="<?php echo count($contacts)?>">

<span class="span7">
	<div id="contacts">
	<?php
	
	$cont = 0;
	if (Utils::hasContent ( $contacts )) {
		foreach ( $contacts as $contact ) {
			// echo $this->renderPartial('_form', array('form'=>$form,'model'=>$contact, 'position'=>$cont++));
			
			echo '<table>' . '<tr><td><label for="Contact_' . $cont . '_contact">Nome*</label></td><td><label for="Contact_' . $cont . '_fone1">Telefone 1</label></td><td><label for="Contact_' . $cont . '_fone2">Telefone 2</label></td><td><label for="Contact_' . $cont . '_type">Tipo</label></td></tr>' . '<tr><td><input class="span3" maxlength="45" name="Contact[' . $cont . '][contact]" id="Contact_' . $cont . '_contact" type="text" value="' . $contact->contact . '"></td>' . '<td><input class="span2" maxlength="45" name="Contact[' . $cont . '][fone1]" id="Contact_' . $cont . '_fone1" type="text" value="' . $contact->fone1 . '"></td>' . '<td><input class="span2" maxlength="45" name="Contact[' . $cont . '][fone2]" id="Contact_' . $cont . '_fone2" type="text" value="' . $contact->fone2 . '"></td>' . '<td><input class="span3" maxlength="45" name="Contact[' . $cont . '][type]" id="Contact_' . $cont . '_type" type="text" value="' . $contact->type . '"></td></tr></table>';
			$cont ++;
		}
	}
	?>
</div>
</span>
<span class="span7"> <input type="button" id="addcontact"
	name="addcontact" value="Adicionar Contato" onClick="addContact()">
<?php if(!$hasContact) { ?>
<p style="color: #b94a48;">Nenhum contato inserido.</p>
<?php }?>
</span>
<br />
<br />